package com.yjhb.android.sbz.v2.activity

import androidx.viewpager.widget.ViewPager
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.activity.BaseActivity
import com.yjhb.android.sbz.v2.activity.rule.V2RuleFissionRewardActivity
import com.yjhb.android.sbz.v2.activity.rule.V2RulePromotionRewardActivity
import com.yjhb.android.sbz.v2.fragment.reward.FragmentFissionRewardV2
import com.yjhb.android.sbz.v2.fragment.reward.FragmentPromotionRewardV2
import com.jojo.android.zxlib.adapter.FragmentAdapter
import com.jojo.android.zxlib.base.BaseFragment
import com.jojo.android.zxlib.base.mvp.BasePresenter
import com.jojo.android.zxlib.tool.ZxActivityTool
import com.jojo.android.zxlib.view.tablayout.listener.OnTabSelectListener
import kotlinx.android.synthetic.main.activity_layout_user_reward_v2.*


/**
 *  创建者 zx
 *  创建时间 2021/4/1 15:20
 */
class PromotionRewardActivityV2 : BaseActivity<BasePresenter<*, *>>() {
    private val fragments = mutableListOf<BaseFragment<*>>()
    private val fragmentPromotionRewardV2 = FragmentPromotionRewardV2()
    private val fragmentFissionRewardV2 = FragmentFissionRewardV2()
    private val titles = arrayOf("推广奖励", "裂变奖励")
    private var currIndex = 0

    override fun initPresenter(): BasePresenter<*, *>? {
        return null
    }

    override fun isCheckLogin(): Boolean {
        return true
    }

    override fun getLayoutId() = R.layout.activity_layout_user_reward_v2

    override fun initUI() {
        segmentTabLayout.setTabData(titles)
        fragments.add(fragmentPromotionRewardV2)
        fragments.add(fragmentFissionRewardV2)
        viewpager.adapter = FragmentAdapter(supportFragmentManager, fragments)
        currIndex = intent.getIntExtra("index", 0)
    }

    override fun initData() {
        viewpager.setCurrentItem(currIndex, true)
    }

    override fun regEvent() {
        back.setOnClickListener { finish() }
        title_right_tv.setOnClickListener { }

        segmentTabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                viewpager.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }
        })
        viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

            }

            override fun onPageSelected(position: Int) {
                segmentTabLayout.currentTab = position
            }
        })
        title_right_tv.setOnClickListener {
            if (viewpager.currentItem == 0) {
                ZxActivityTool.skipActivity(activity, V2RulePromotionRewardActivity::class.java)
            } else {
                ZxActivityTool.skipActivity(activity, V2RuleFissionRewardActivity::class.java)
            }
        }
    }

}